home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / VideoToolbox 97.08.16 / VideoToolboxSources / SetFileInfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-10  |  3.6 KB  |  119 lines  |  [TEXT/CWIE]

  1. /*
  2. SetFileInfo.c
  3.  
  4. USAGE
  5.  
  6.     SetFileInfo("Output File",'xxxx','yyyy');
  7.  
  8. ARGUMENTS
  9.  
  10.     char    *fileName;        The name of the file (including HFS
  11.                             directory name) to be set.
  12.     
  13.     OStype    'xxxx'            The four character file type, eg 'TEXT'
  14.  
  15.     OStype    'xxxx'            The four character creator, eg 'XCEL','CGRF','QKPT','QED1'
  16.  
  17. COMMENTS
  18.  
  19.     The syntax 'xxxx' results in four characters packed into a short int. This is
  20.     a Macintosh convention, not Standard C. That's ok since this routine is strictly
  21.     Macintosh anyway.
  22.  
  23.     As far as I can tell the ChangeCreatorType function in Apple's MoreFilesExtras.c
  24.     does the same thing, but with more precautions. We probably should use it
  25.     instead. It automatically calls FSpBumpDate, if appropriate.
  26.  
  27. EXAMPLE
  28.  
  29.     ** create Cricket data file **
  30.     myFile=fopen("LuminanceCalibration.data","w");
  31.     SetFileInfo("LuminanceCalibration.data",'TEXT','CGRF');
  32.     fprintf(myFile,"*\n");
  33.     fprintf(myFile,"x\ty\n");
  34.     for(i=0;i<n;i++)fprintf(myFile,"%9g\t%9g\n",x[i],y[i]);
  35.     fclose(myFile);
  36.  
  37. REFERENCE:
  38.  
  39.     >From blob@ricochet.net
  40.     Date: Sun, 01 Dec 1996 11:07:54 -0700
  41.     Organization: (none)
  42.     
  43.     In article <32A1BDC9.149A@uclink4.berkeley.edu>,
  44.     cwright@uclink4.berkeley.edu wrote:
  45.     
  46.     > I've written a small app to quickly change the Creator/File type of a
  47.     > file.  It works fine, but after it changes these, the Finder does not
  48.     > update the file until you do a Get Info or close and open the folder
  49.     > that the file is in so that it has to reread the file info again.  
  50.     
  51.     This is answered in the FAQ at <http://www.best.com/~ckt/faq/>, with sample
  52.     code in MoreFiles. (BumpDate in MoreFilesExtras.c)  You need to change the modification date of the parent
  53.     folder, or send the scriptable Finder an event to update its display.
  54.     
  55.     See <http://www.best.com/~ckt/faq/Four.html#30> for details.
  56.     
  57.     
  58. HISTORY
  59. 12/87    EJC wrote q_make_crick()
  60. 8/89    dgp Renamed and rewritten.
  61. 8/24/91    dgp    Made compatible with THINK C 5.0.
  62. 12/28/92 dgp Removed obsolete support for THINK C 4.
  63. 4/10/97    dgp    Eliminate stuff that was conditional on !UNIVERSAL_HEADERS.
  64.  
  65. *****************************************************************************/
  66. #include "VideoToolbox.h"    /* for prototype of itself */
  67. //#include <Files.h>
  68.  
  69. /*
  70. COMMENT:
  71. As far as I can tell the ChangeCreatorType function in Apple's MoreFilesExtras.c
  72. does the same thing as SetFileInfo, but with more precautions. We probably should use it
  73. instead. It automatically calls BumpDate, if appropriate.
  74. */
  75. void SetFileInfo(char *fileName,OSType fileType,OSType fileCreator)
  76. {
  77.     FInfo outFileInfo;
  78.     
  79.     c2pstr(fileName);
  80.     GetFInfo((StringPtr)fileName,0,&outFileInfo);
  81.     outFileInfo.fdType = fileType;
  82.     outFileInfo.fdCreator = fileCreator;
  83.     SetFInfo((StringPtr)fileName,0,&outFileInfo);
  84.     p2cstr((void *)fileName);
  85. }
  86.  
  87. /*
  88. Changing the ioDrMdDat field of your file's parent directory forces the
  89. Finder into updating its window. This is useful after you've changed a file's
  90. type, to get the Finder to immediately show the new icon.
  91.  
  92. HISTORY:
  93. Craig Marciniak, TemplarDev@aol.com, published in March, 1995 issue of MacTech Magazine, p. 80.
  94.  
  95. COMMENT:
  96. As far as I can tell the FSpBumpDate in Apple's MoreFilesExtras.c does the same thing, but with
  97. more precautions. We probably should use it instead.
  98. */
  99. #include <LowMem.h>        // LMGetTime
  100. void ForceFinderToUpdateFileIcon(FSSpecPtr file);
  101.  
  102. void ForceFinderToUpdateFileIcon(FSSpecPtr file)
  103. {
  104.     CInfoPBRec tempPB;
  105.  
  106.     if(file != 0L){
  107.         tempPB.dirInfo.ioNamePtr=0L;
  108.         tempPB.dirInfo.ioVRefNum=file->vRefNum;
  109.         tempPB.dirInfo.ioFDirIndex=-1;
  110.         tempPB.dirInfo.ioDrDirID=file->parID;
  111.         if(PBGetCatInfoSync(&tempPB)==noErr){
  112.             tempPB.dirInfo.ioDrMdDat=LMGetTime();
  113.             tempPB.dirInfo.ioDrDirID=file->parID;
  114.             PBSetCatInfoSync(&tempPB);
  115.         }
  116.     }
  117. }
  118.         
  119.